<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<link rel="stylesheet" href="../../layui/css/layui.css">
<link rel="stylesheet" href="../../layui/dtree/dtree.css">
<link rel="stylesheet" href="../../layui/dtree/font/iconfont.css">
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../layui/dtree/dtree.js"></script>
<head>
<meta charset="UTF-8">
<title>组织级别树</title>
</head>
<body>
<div style="height: 550px; overflow: auto;" id="toolbarDiv3">
  <ul id="toolbarTree3" class="dtree" data-id="0"></ul>
</div>
<script>
layui.config({
	  base: '../layui/dtree/' //配置 layui 第三方扩展组件存放的基础目录
	}).extend({
	  dtree: 'dtree' //定义该组件模块名
	}).use(['element','layer', 'dtree'], function(){
		var layer = layui.layer,
	    dtree = layui.dtree,
	    $ = layui.$;
	var leaf=null;
	dtree.render({
	  icon:4,
	  elem: "#toolbarTree3",
	  url: "",
	  toolbar:true,
	  toolbarScroll:"#toolbarDiv3",
	  toolbarStyle: {
		   title: "菜单",
		   area: ["50%", "400px"]
		  },
	  toolbarShow:["add","edit"],
	  toolbarBtn: [
		  [
			  {"label":"级别","name":"level","type":"text"},{"label":"下拉","name":"test","type":"select","optionsData":{"1":"男","2":"女","3":"未知","4":"泰国归来"}}
			  ],[{"label":"状态","name":"state","type":"select","optionsData":{"1":"正常","2":"禁用"}}]
		  ],
	  toolbarFun: {
	      	addTreeNode: function(treeNode){
	      		var nodeId=0;
		    	$.ajax({
		              url:'addOrganization',
		              type:'post',
		              data:{'parentId':treeNode.parentId,'oName':treeNode.addNodeName},
		              dataType: 'json',                
		              success: function(nodeId){
		            	  if(nodeId!=null){
		            		  treeNode.nodeId=nodeId;
		            	  }
		            	  }
		              }); 
		      return treeNode.nodeId;
	        },
		    editTreeNode: function(treeNode){
		    	 var param = $.ajax({
		    		async:false,
		    		url:'update',
		    		type:'post',
					data:{'oid':treeNode.nodeId,'state':treeNode.state},
					dataType: 'json',
					success: function(treenode){
		            	  if(treenode!=null){
		            		  return treenode;
		            	  }
		            	 }
		    		})
		      return param; 
		    },
		    loadToolbarBefore: function(buttons, treeNode, $div){ // 右键菜单加载前的函数
		    return buttons; // 返回按钮组，如不返回则按钮将不会显示。
		  }
		}
	  
	});
	});

</script>
</body>
</html>